//
//    Tokaplot
//    https://code.google.com/p/tokaplot/
//
//    License: GPL v3
//    https://code.google.com/p/tokaplot/wiki/License
//
//    This file is part of Tokaplot.
//
//    Tokaplot is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    Tokaplot is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with Tokaplot.  If not, see <http://www.gnu.org/licenses/>
//

package com.tokaplot;

public class DiagnosticInfo {
	
	// Diagnostic info flags
	public final static int DIAG_CAN_USE_TELEPHONY 		= 0x0001;
	public final static int DIAG_CAN_USE_ACCELEROMETER 	= 0x0002;
	public final static int DIAG_CAN_USE_MAGNETIC_FIELD = 0x0004;
	public final static int DIAG_USING_SENSORS 			= 0x0008;
	public final static int DIAG_USING_GPS 				= 0x0010;
	public final static int DIAG_CAN_USE_GPS_SPEED 		= 0x0020;
	public final static int DIAG_CAN_USE_GPS_ALT 		= 0x0040;
	public final static int DIAG_CAN_USE_LIGHT 			= 0x0080;
	public final static int DIAG_CAN_READ_CPU 			= 0x0100;
	public final static int DIAG_CAN_READ_NET 			= 0x0200;
	public final static int DIAG_CAN_READ_MEM 			= 0x0400;
	public final static int DIAG_CAN_READ_CUR	 		= 0x0800;
	public final static int DIAG_CAN_READ_CPL	 		= 0x1000;
	
	public final static int DIAG_ERROR_FILE_OPEN_CPU	= 0x0001;
	public final static int DIAG_ERROR_FILE_READ_CPU	= 0x0002;
	public final static int DIAG_ERROR_FILE_OPEN_CPL	= 0x0004;
	public final static int DIAG_ERROR_FILE_READ_CPL	= 0x0008;
	public final static int DIAG_ERROR_FILE_OPEN_MEM	= 0x0010;
	public final static int DIAG_ERROR_FILE_READ_MEM	= 0x0020;
	public final static int DIAG_ERROR_FILE_OPEN_NET	= 0x0040;
	public final static int DIAG_ERROR_FILE_READ_NET	= 0x0080;
	public final static int DIAG_ERROR_FILE_OPEN_CUR	= 0x0100;
	public final static int DIAG_ERROR_FILE_READ_CUR	= 0x0200;
	
	// Diagnostic info values
	private int diagFlags;				// Diagnostic flags
	private int diagErrors;				// Diagnostic error flags
	private float diagDataFraction1;	// Data 1 buffer fraction
	private float diagDataFraction2;	// Data 2 buffer fraction
	private float diagRenderBuffer1;	// Render buffer 1 % fill
	private float diagRenderBuffer2;	// Render buffer 2 % fill
	public String dLicence;				// License string
	
	public boolean checkFlag(int bFlag) {
		return ((diagFlags&bFlag) != 0);
	}
	public void toggleFlag(int bFlag) {
		diagFlags ^= bFlag;
	}
	public void setFlag(int bFlag) {
		diagFlags |= bFlag;
	}
	public void clearFlag(int bFlag) {
		diagFlags &= ~bFlag;
	}
	public boolean checkError(int bError) {
		return ((diagErrors&bError) != 0);
	}
	public void toggleError(int bError) {
		diagErrors ^= bError;
	}
	public void setError(int bError) {
		diagErrors |= bError;
	}
	public void clearError(int bError) {
		diagErrors &= ~bError;
	}	
	public void setDataFraction(int index, float value) {
		if (index == 1) {
			diagDataFraction1 = value;
		} else if (index == 2) {
			diagDataFraction2 = value;
		}		
	}
	public float getDataFraction(int index) {
		if (index == 1) {
			return diagDataFraction1;
		} else if (index == 2) {
			return diagDataFraction2;
		}
		return 0.0f;
	}	
	public void setRenderBufferLevel(int index, float value) {
		if (index == 1) {
			diagRenderBuffer1 = value;
		} else if (index == 2) {
			diagRenderBuffer2 = value;
		}		
	}
	public float getRenderBufferLevel(int index) {
		if (index == 1) {
			return diagRenderBuffer1;
		} else if (index == 2) {
			return diagRenderBuffer2;
		}
		return 0.0f;
	}
	
	public DiagnosticInfo() {
		diagFlags 			= 0;
		diagErrors 			= 0;
		diagDataFraction1 	= 0.0f;
		diagDataFraction2 	= 0.0f;
		diagRenderBuffer1 	= 0.0f;
		diagRenderBuffer2 	= 0.0f;
	}
	
	public DiagnosticInfo(DiagnosticInfo pDiagnosticInfo) {
		diagFlags 			= pDiagnosticInfo.diagFlags;
		diagErrors 			= pDiagnosticInfo.diagErrors;
		diagDataFraction1 	= pDiagnosticInfo.diagDataFraction1;
		diagDataFraction2 	= pDiagnosticInfo.diagDataFraction2;
		diagRenderBuffer1 	= pDiagnosticInfo.diagRenderBuffer1;
		diagRenderBuffer2 	= pDiagnosticInfo.diagRenderBuffer2;
	}
}
